<!--
 * @Descripttion: 抽屉实现
 * @version: 
 * @@Company: None
 * @Author: 孤鹜
 * @Date: 2022-01-27 11:11:35
 * @LastEditors: 孤鹜
 * @LastEditTime: 2022-01-28 10:17:32
-->
<template>
  <div id="drawer_container">
    <!-- 包含两个部分，一个部分为幕布，出现时将整个页面覆盖，另一部分则为抽屉内容 -->
    <div id="drawer_canvas" @click="backTo()"></div>
    <div id="drawer">
      <div id="drawer_close_btn"><img src="../assets/fault.svg" @click="backTo()"/></div>
      <div id="drawer_white_space"></div>
      <img id="user_img" :src="user_img" alt="人像区域"/>
      <table id="user_msg_box">
        <tr class="user_msg_tr">
          <td class="user_msg_td">用户名：</td>
          <td class="user_msg_td">{{user_name}}</td>
        </tr>
        <tr class="user_msg_tr">
          <td class="user_msg_td">备注：</td>
          <td class="user_msg_td"><div id="user_msg_tag">{{user_tag}}</div></td>
        </tr>
      </table>
      <button id="login_out" @click="loginOut()">退出登录</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user_img: this.$store.state.user_img,
      user_name: this.$store.state.user_name,
      user_tag: this.$store.state.user_type,
    }
  },
  mounted() {
    // 控制备注样式
    let user_msg_tag = document.getElementById('user_msg_tag')
    let isStudent = this.user_tag === '学生' ? true : false
    this.loadChangeTagType(user_msg_tag, isStudent)
  },
  methods: {
    loadChangeTagType(user_msg_tag, isStudent) {
      if(isStudent) {
        user_msg_tag.classList.add('isStudent')
      }
      else {
        user_msg_tag.classList.add('isTeacher')
      }
    },
    loginOut() {
      // 退出登录
      if(true) console.log('loginOut');
    },
    popDrawer() {
      let drawer_container = document.getElementById('drawer_container')
      let drawer_canvas = document.getElementById('drawer_canvas')
      let popMarginLeft = document.getElementById('drawer').clientWidth
      drawer_canvas.style.zIndex = 1000
      drawer_container.style.marginLeft = popMarginLeft
    },
    backTo() {
      let drawer_container = document.getElementById('drawer_container')
      let drawer_canvas = document.getElementById('drawer_canvas')
      drawer_canvas.style.zIndex = -10
      drawer_container.style.marginLeft = 0
    }
  }
}
</script>

<style>
#drawer_container {
  width: 120%;
  height: 100%;
  position: absolute;
}
#drawer_canvas {
  width: 83.3%;
  height: 100%;
  float: left;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: -10;
}
#drawer {
  width: 16.7%;
  height: 100%;
  float: left;
  border: 1px solid #f3f3f3;
  box-shadow: -5px 0 5px #ddd;
  display: flex;
  flex-flow: column nowrap;
  align-items: center;
  background: #fafafa;
}
#drawer_close_btn {
  flex: 0 0 5%;

  width: 100%;
  display: flex;
  justify-content: flex-end;
}
#drawer_close_btn>img{
  width: 18px;
  cursor: pointer;
  stroke: #ebebeb;
  margin: 8px;
}
#drawer_white_space {
  flex: 0 0 10%;
}
#user_img {
  height: 90px;
  width: 90px;
  border-radius: 50%;
  background-color: #555;
  margin-bottom: 40px;
}
#user_msg_box {
  flex: 0 0 10%;
  font-family: 'Courier New', Courier, monospace;
  font-weight: 600;
  font-size: 18px;
  max-width: 80%;
}
.user_msg_tr, .user_msg_td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#user_msg_tag {
  width: 38px;
  padding: 5px 0px 5px 10px;
  letter-spacing: 4px;
  font-size: 12px;
  font-weight: 400;
  border-radius: 3px;
  /* box-shadow: 1px 1px 2px #ddd; */
}
.isStudent {
  border-color: #ddeeff;
  color: #6cb3ff;
  background-color: #ecfeff;
}
.isTeacher {
  border-color: #e4f4dc;
  color: #78c850;
  background-color: #f0f9eb;
}
#login_out {
  height: 35px;
  width: 80%;
  border-radius: 5px;
  border: 1px solid #fbc7c7;
  background-color: #f56c6c;
  color: #fdecec;
  margin-top: 130px;
  cursor: pointer;
}
</style>